package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class LoginDAO {
	
	private Connection conexao = FabricaConexoesBanco.getInstancia().getConexao();
	
	public boolean efetuarLogin(int matricula, String senha) {
		String sql = "SELECT 1 FROM login where pk_matricula = ? and senha = ?";
		boolean logou = false;

		try {
			PreparedStatement pstmt = conexao.prepareStatement(sql);
			pstmt.setInt(1, matricula);
			pstmt.setString(2, senha);

			ResultSet rs = pstmt.executeQuery();

			if(rs.next()){
				logou = true;
			}
		} catch (SQLException e) {

			e.printStackTrace();
		}
		return logou;
	}
	
	
	public void inserir(int matricula, String senha){
		
		String sql = "INSERT INTO login (pk_matricula, senha) values(?,?)";

		try {
			PreparedStatement pstmt = conexao.prepareStatement(sql);

			pstmt.setInt(1, matricula);
			pstmt.setString(2, senha);

			pstmt.execute();

			pstmt.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

}
